/*
 * Copyright (c) 2009, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _TSSP_INTERNAL_H_
#define _TSSP_INTERNAL_H_

#include "config.h"

#if STDC_HEADERS
#include <stdio.h>
#endif

#if HAVE_STRING_H
#include <string.h>
#endif 
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif

#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif

#ifdef HAVE_ASSERT_H
#include <assert.h>
#else
#define assert(expr)
#endif

#include "tssp.h"

#ifdef WIN32
#ifndef int16_t
#define int16_t short
#endif
#ifndef uint16_t
#define uint16_t unsigned short
#endif
#ifndef int32_t
#define int32_t int
#endif
#ifndef uint32_t
#define uint32_t unsigned int
#endif
#ifndef socklen_t
#define socklen_t int
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifdef NDEBUG
#define TSSP_LOG(...)
#define TSSP_TRACE(x)
#define TSSP_ASSERT(expr)
#else
#define TSSP_LOG                printf
#define TSSP_TRACE(x)           TSSP_LOG("%s: %s\n", __FUNCTION__, x)
#define TSSP_ASSERT             assert
#endif

#define TSSP_MIN(a, b)          ((a) < (b) ? (a) : (b))

#ifdef __GNUC__
#define likely(x)    __builtin_expect((x), 1)
#define unlikely(x)  __builtin_expect((x), 0)
#else
#define likely(x)    (x)
#define unlikely(x)  (x)
#endif

int tssp_impl_init(struct tssp *parser);

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif /* _TSSP_INTERNAL_H_ */

